/**
 * 
 */
package com.photoinfo.test.app;

import java.util.Iterator;

import org.testng.annotations.Test;

import com.drew.imaging.ImageMetadataReader;
import com.drew.imaging.ImageProcessingException;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;
import com.photoinfo.test.AbstractTest;

/**
 * @author Holz, Roberto
 * 
 *         created 20.04.2008 | 11:53:58
 */
@SuppressWarnings("unchecked")
public class ReadingEXIF extends AbstractTest {

	public ReadingEXIF() {
		super();
	}

	// @Test
	public void testReadRAW() throws ImageProcessingException {
		log.debug("testReadRAW -------------------------------");
		Metadata metadata = ImageMetadataReader.readMetadata(imgD200RAW);
		// iterate through metadata directories
		Iterator<Directory> directories = metadata.getDirectoryIterator();
		while (directories.hasNext()) {
			Directory directory = directories.next();
			// iterate through tags and print to System.out
			Iterator<Tag> tags = directory.getTagIterator();
			while (tags.hasNext()) {
				Tag tag = tags.next();
				outputTag(tag);
			}
		}
	}

	@Test
	public void testReadJPEG() throws ImageProcessingException {
		log.debug("testReadJPEG ------------------------------");
		Metadata metadata = ImageMetadataReader.readMetadata(imgD200JPG);
		// iterate through metadata directories
		Iterator<Directory> directories = metadata.getDirectoryIterator();
		while (directories.hasNext()) {
			Directory directory = directories.next();
			// iterate through tags and print to System.out
			Iterator<Tag> tags = directory.getTagIterator();
			while (tags.hasNext()) {
				Tag tag = tags.next();
				outputTag(tag);
			}
		}
	}

	@Test
	public void testReadJPEGKonica() throws ImageProcessingException {
		log.debug("testReadJPEGKonica ------------------------------");
		Metadata metadata = ImageMetadataReader.readMetadata(imgZ10);
		// iterate through metadata directories
		Iterator<Directory> directories = metadata.getDirectoryIterator();
		while (directories.hasNext()) {
			Directory directory = directories.next();
			// iterate through tags and print to System.out
			Iterator<Tag> tags = directory.getTagIterator();
			while (tags.hasNext()) {
				Tag tag = tags.next();
				outputTag(tag);
			}
		}
	}

	@Test
	public void testReadJPEGnoEXIF() throws ImageProcessingException {
		log.debug("testReadJPEGnoEXIF ------------------------------");
		Metadata metadata = ImageMetadataReader.readMetadata(imgNoEXIF);
		// iterate through metadata directories
		Iterator<Directory> directories = metadata.getDirectoryIterator();
		while (directories.hasNext()) {
			Directory directory = directories.next();
			// iterate through tags and print to System.out
			Iterator<Tag> tags = directory.getTagIterator();
			while (tags.hasNext()) {
				Tag tag = tags.next();
				outputTag(tag);
			}
		}
	}
	
	@Test
	public void testReadPNGnoEXIF() throws ImageProcessingException {
		log.debug("testReadPNGnoEXIF ------------------------------");
		Metadata metadata = ImageMetadataReader.readMetadata(imgNoEXIFwrongFormat);
		// iterate through metadata directories
		Iterator<Directory> directories = metadata.getDirectoryIterator();
		while (directories.hasNext()) {
			Directory directory = directories.next();
			// iterate through tags and print to System.out
			Iterator<Tag> tags = directory.getTagIterator();
			while (tags.hasNext()) {
				Tag tag = tags.next();
				outputTag(tag);
			}
		}
	}

	private void outputTag(Tag tag) {
		log.debug("Tag: "+tag);
	}
}
